package org.openzip.openzip.gui.util;

import java.io.File;
import java.util.ArrayList;
import java.util.Collection;

public class FileUtil
{
	private static Collection<File> utilCol = new ArrayList<File>();
	
	public static Collection<File> getLeafs(File f, boolean includeDirs){
		utilCol.clear();
		if(f.isFile()){
			utilCol.add(f);
			return new ArrayList<File>(utilCol);
		}
		load(f, includeDirs);
		return new ArrayList<File>(utilCol);
	}
	
	private static void load(File f, boolean includeDirs){
		File[] files = f.listFiles();
		if(files == null){
			return;
		}
		if(includeDirs){
			utilCol.add(f);
		}
		for(int i = 0; i<files.length; i++){
			if(files[i].isDirectory()){
				load(files[i], includeDirs);
			}
			else{
				utilCol.add(files[i]);
			}
		}
	}
	
	public static String[] splitFilePath(File f){
		String separator = System.getProperty("file.separator").replaceAll("\\\\", "\\\\\\\\");
		return f.getAbsolutePath().split(separator);
	}
}
